import { defineStore } from "pinia";
import type { AppState } from "../types";

export const useAppStore = defineStore("app", {
    state: (): AppState => ({
        indexNav: 0
    }),

    getters: {
        /**
         * 获取当前 tabbar 索引
         */
        currentTabIndex: (state): number => {
            return state.indexNav;
        }
    },

    actions: {
        /**
         * 设置 tabbar 索引
         */
        setIndexNav(index: number) {
            this.indexNav = index;
        },

        /**
         * 切换到指定 tabbar
         */
        switchTab(index: number) {
            this.setIndexNav(index);
        }
    }
});
